# Maintainer: Daniel M. Capella <polyzen@archlinux.org>
# Contributor: Jeffrey Zhang <zhang.lei.fly@gmail.com>

pkgname=esbonio
pkgver=0.16.2
pkgrel=1
pkgdesc='Language server for working with Sphinx projects'
arch=('any')
url=https://docs.esbon.io/
license=('MIT')
depends=(
  'python-platformdirs'
  'python-pygls'
  'python-pyspellchecker'
  'python-sphinx'
)
makedepends=(
  'git'
  'python-build'
  'python-installer'
  'python-setuptools'
  'python-wheel'
)
conflicts=("python-$pkgname")
replaces=("python-$pkgname")
checkdepends=('python-pytest-lsp' 'python-pytest-timeout')
source=("git+https://github.com/swyddfa/$pkgname.git#tag=$pkgname-language-server-v$pkgver")
b2sums=('SKIP')

build() {
  cd $pkgname/lib/$pkgname
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd $pkgname/lib/$pkgname
  python -m venv --system-site-packages test-env
  test-env/bin/python -m installer dist/*.whl
  PATH="$PWD/test-env/bin:$PATH" test-env/bin/python -m pytest
}

package() {
  cd $pkgname/lib/$pkgname
  python -m installer --destdir="$pkgdir" dist/*.whl

  # Symlink license file
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  install -d "$pkgdir"/usr/share/licenses/$pkgname
  ln -s "$site_packages"/$pkgname-$pkgver.dist-info/LICENSE \
    "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
}
